<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="${pageContext.request.contextPath}/resources/jslib/jquery-easyui-1.4.1/themes/bootstrap/easyui.css" rel="stylesheet" />
<link href="${pageContext.request.contextPath}/resources/jslib/jquery-easyui-1.4.1/themes/icon.css" rel="stylesheet" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/assets/css/font-awesome.min.css" />
</head>
<body>

<table id="tb_privilege" data-options="fit:true,border:false" ></table>

		<%@include file="/jsps/inc.jsp" %>
		<script type="text/javascript" src="${pageContext.request.contextPath}/resources/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/system.js"></script>

		<script type="text/javascript">
		system.pixel_0="<%=contextPath%>/resources/images/pixel_0.gif";
		var grid;
		function addFun(id){
			var dialog=parent.bootstrapQ.dialog({
				title:"添加子权限",
				 okbtn : '添加',
				url:'<%=contextPath%>/jsps/securityJsp/auth/privilege-form.jsp?method=add&id='+id
			},function(){
				parent.submitForm(grid,parent.$,parent.bootstrapQ);
				return true;
			})
		}
		function editFun(id){
			var dialog=parent.bootstrapQ.dialog({
				title:"编辑权限",
				 okbtn : '更新',
				url:'<%=contextPath%>/securityJsp/auth/privilege-form.jsp?method=update&id='+id
			},function(){
				parent.submitForm(grid,parent.$,parent.bootstrapQ);
				return true;
			})
		}
		function delFun(id)
		{
			$.post("<%=contextPath%>/privilege/delete.action", {'id':id}, function(result) {
				if(result.success)
				{
					grid.treegrid('reload');
				}
				else
				{
					parent.bootstrapQ.alert(result.msg);
				}
			});
		}
		$(function(){
			grid=$("#tb_privilege").treegrid({
				title:'',
				url:'<%=contextPath%>/privilege/privileges.action',
				idField : 'id',
				treeField : 'name',
				animate:true,
				rownumbers : true,
				autoRowHeight:false,
				rowStyler: function(index,row){
					return "height:40px";
				},
				loadMsg:"正在加载中，请稍候...",
				frozenColumns : [ [ {
					width : 200,
					height:100,
					title : '资源名称',
					field : 'name'
				} ] ],
				columns : [ [
				  	{
					  	width : 200,
					  	height:100,
						title : '权限路径',
						field : 'url',
						formatter : function(value, row) {
							if(value){
								return system.formatString('<span title="{0}">{1}</span>', value, value);
							}
						} 
				  	},
				  	{
						width : 60,
						height:100,
						title : '权限类型',
						align:'center',
						field : 'privilegeType',
						formatter : function(value, row) {
							if(value==="MENU")
								return "菜单";
							else if(value==="FUNCTION")
								return "功能";
							else if(value==="BUTTON")
								return "按钮";
							else if(value==="URL")
								return "链接";
						}
					},
					{
						width : 60,
						height:100,
						title : '是否启用',
						field : 'privilegeEnabled',
						align:'center',
						formatter:function(value,row){
							if(value)
								return '<input type="checkbox" disabled="disabled" checked/>';
							else
								return '<input type="checkbox" disabled="disabled"/>';
						}
						
					},
					{
						width : 200,
						height:100,
						title : '权限描述',
						field : 'description',
						formatter : function(value, row) {
							if(value){
								return system.formatString('<span title="{0}">{1}</span>',value,value);
							}
						}
					},
					{
						title : '操作',
						height:100,
						field : 'aa',
						width : 80,
						formatter : function(value, row) {
							var str='';
							if(row.url&&row.privilegeType=="MENU")
								str+=system.formatString('&nbsp;&nbsp;<i class="icon-plus" onClick="addFun(\'{0}\')" title="添加子权限" style="cursor:pointer;"/>',row.id);
							else if(row.privilegeType=="FUNCTION")
							{
								str+=system.formatString('&nbsp;&nbsp;<i class="icon-edit" onClick="editFun(\'{0}\')" title="编辑权限" style="cursor:pointer;"/>',row.id);
								str+=system.formatString('&nbsp;&nbsp;&nbsp;<i class="icon-remove" onClick="delFun(\'{0}\')" title="删除权限" style="cursor:pointer;"/>&nbsp;&nbsp;',row.id);
							}
							return str;
							
						}
					}
				 ]],
				 onBeforeLoad : function(row, param) {
						/* parent.$.messager.progress({
							text : '数据加载中....'
						}); */
				},
				onLoadSuccess : function(row, data) {
					
						$('.iconImg').attr('src', system.pixel_0);
						/* parent.$.messager.progress('close'); */
				},
				onLoadError:function(){
					parent.bootstrapQ.alert("数据加载失败");
				}
				
			})
			$("tr").css('background-color','#438EB9').css('height','40px');
		})
	</script>

</body>
</html>